import { Component, OnInit } from '@angular/core';
import {HttpService} from '../../../lib/service/http.service';
import {adSystemApiUrl} from '../../../../config/api';

@Component({
  selector: 'client-intent',
  templateUrl: 'client-intent.component.html',
  styleUrls: ['client-intent.component.scss'],
  providers: []
})
export class ClientIntentComponent implements OnInit {

  clientList = [];
  searchData: number;
  totalItems: number;
  currentPage: number = 1;
  itemsPerPage: number = 12;
  constructor(private httpService: HttpService) { }

  ngOnInit() {
    this.getAgentList(1);
  }
  //重置
  reset(){
    this.searchData = null;
    this.getAgentList(1);
  }
  //搜索
  search(){
    this.getAgentList(1,this.searchData);
  }

  // 获取意向代理商列表
  getAgentList(page: number,mobile?: number){
    if(!!mobile) {
      var url = `${adSystemApiUrl}/v1/admin/applet_apply/list?mobile=${mobile}&type=意向客户&page=${page}&pageSize=${this.itemsPerPage}`;
    }else{
      var url = `${adSystemApiUrl}/v1/admin/applet_apply/list?type=意向客户&page=${page}&pageSize=${this.itemsPerPage}`;
    }
    return this.httpService.httpGetAuth(url)
      .subscribe(
        res => {
          this.totalItems = res.data.total;
          this.clientList = res.data.data;
        }
      )
  }

  pageChanged(event: any): void {
    this.getAgentList(event.page,this.searchData);
  }
}
